﻿<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="onein" uri="http://www.onein.cn/jsp/taglib"%>
<html>
<head>
<meta content="text/html; charset=uft-8" http-equiv="Content-Type" />
<script src="<onein:url value="/js/jquery.js"/>" type="text/javascript"></script>
<script src="<onein:url value="/ckeditor/ckeditor.js"/>" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
 function chg(){
    var section = document.getElementById('sectionId').value;
	if(section == ''){
	   $('#categoryId').empty();
       return;
	}
   $.post("getCategory.htm",{  
	   sectionId: section
	        }, function(data){ 
		        $('#categoryId').empty();
		        $(data).appendTo("#categoryId");
	        },'text' 
	   ) 
}

 function getdate_onclick(dobj){
	 dateobj=document.getElementById(dobj);
	 origin=dateobj.value;
	 tmpstr=window.showModalDialog("../inc/getdatetime.jsp?showtime=off","aa","dialogWidth:250px;dialogHeight:230px;Center:1;status:no;help:no");
	 if(tmpstr=="gtm"){
	 dateobj.value=origin;}
	 else{
	 dateobj.value=tmpstr;}

	 }


</script>
<div id="errorDIV" style="color:red"></div>
<div id="infoDIV" style="color:green"><c:if test="${flag == 'success'}">增加文章成功!</c:if></div>
<form action="add.htm" name="learnContentFrom" method="post" onsubmit="return validate();">
<table>
	<tr>
		<td>一级分类</td>
		<td><select id="sectionId" name="section" onChange="chg()">
			<option value="">--select section--</option>
			<c:forEach var="section" items="${sections}">
				<option value="${section.id}" <c:if test="${section.id == selSection}">selected</c:if>>${section.title}</option>
			</c:forEach>
		</select></td>
	</tr>
	<tr>
		<td>二级分类</td>
		<td><select id="categoryId" name="categoryId">
		   ${selCategory}
		</select>必填</td>
	</tr>
	<tr>
		<td>标题</td>
		<td><input type="text" id="title" name="title" size="100"/>必填</td>
	</tr>
	<tr>
		<td>原作者</td>
		<td><input type="text" name="author" size="100"/></td>
	</tr>
	<tr>
		<td>引用URL</td>
		<td><input type="text" id="refUrl" name="refUrl" size="100"/></td>
	</tr>
	<tr>
		<td><a href="#" id=getptime
			onclick="return getdate_onclick('eDate')">原文章日期</a></td>
		<td><input type="text" id="eDate" name="contentDate" size="100"
			value="<%=request.getParameter("edate") == null ? "" : request
					.getParameter("edate")%>"
			readonly="true"></td>
	</tr>
	<tr>
		<td>Tags</td>
		<td><input type="text" name="tags" size="100"/></td>
	</tr>
	<tr>
        <td>文章摘要</td>
        <td><textarea name="introText" id="introText" cols="100" rows="2"></textarea>必填</td>
    </tr>
	<tr>
		<td>文章内容</td>
		<td><textarea name="fullText" id="fullText" cols="100" rows="35"></textarea></td>
	</tr>
	<tr>
		<td colspan=2 align="center"><input type="submit" value="提交" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input
			type="reset" value="重置" /></td>
	</tr>
</table>
</form>

<script type="text/javascript">
    CKEDITOR.replace( 'fullText',
     {
      skin : 'office2003',
      language : 'zh-cn'
     });

    function validate(){
    	setTimeout("check()",50);
    	return false;
    }

    function check(){
    	   var errInfo="";
    	   var hasErr = false
    	   var categoryId = document.getElementById("categoryId");
    	   var title = document.getElementById("title");
    	   var introText = document.getElementById("introText");
    	   var fullText = document.getElementById("fullText");
    	   var refUrl = document.getElementById("refUrl");

    	   if(categoryId.value == ""){
    		   categoryId.focus();
    		   hasErr = true;
    		   errInfo="类别不能为空!<br/>";
    	   }
    	   if(title.value == ""){
    		   title.focus();
    		   hasErr = true;
    		   errInfo+="标题不能为空!<br/>";
    	   }
    	   if(introText.value == ""){
    		   introText.focus();
               hasErr = true;
               errInfo+="文章摘要不能为空!<br/>";
           }
    	   if(fullText.value == ""){
    		   fullText.focus();
    		   hasErr = true;
    		   errInfo+="文章内容不能为空!<br/>";
    	   }
    	   if(refUrl.value != ""){
    		   var regExp = /(http[s]?|ftp):\/\/[^\/\.]+?\..+\w$/i;
    		   var urlString = refUrl.value;
    		   if (!urlString.match(regExp)){
    			   refUrl.focus();
    			   hasErr = true;
    			   errInfo+="URL格式不对!<br/>";
    		   }
    	   }

    	   if(hasErr){
    		   var propertyErr = document.getElementById('errorDIV');
    		   var propertyInfo = document.getElementById('infoDIV');
    		   propertyErr.innerHTML = '';
    		   propertyInfo.innerHTML = '';
    		   propertyErr.innerHTML = errInfo;
    	     return ;
    	   }else{
    		   document.learnContentFrom.submit();
    	   }	   
    	 }
	 
   </script>
   
</body>
</html>